package com.xbh.management.security;

import cn.hutool.crypto.digest.MD5;
import com.xbh.management.filter.TokenLoginFilter;
import com.xbh.management.utils.MD5Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @program: management-center
 * @description: 密码加密
 * @author: 许宝华
 * @create: 2021-10-05 14:47
 */

/**
 * 密码加密校验
 */
@Component
public class DefaultPasswordEncoderUtil implements PasswordEncoder {

    private static Logger log = LoggerFactory.getLogger(DefaultPasswordEncoderUtil.class);


    public DefaultPasswordEncoderUtil(){
        this(-1);
    }

    public DefaultPasswordEncoderUtil(int strLength){

    }

    /**
     * 进行MD5密码加密
     * @param rawPassword
     * @return
     */
    @Override
    public String encode(CharSequence rawPassword) {
        return MD5Utils.encrypt(rawPassword.toString());

    }

    /**
     * 进行密码比较
     * @param rawPassword
     * @param encodedPassword
     * @return
     */
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        log.info("DefaultPasswordEncoderUtil---->前端传入的密码rawPassword==="+rawPassword.toString());
        log.info("DefaultPasswordEncoderUtil---->数据库中的密码encodedPassword==="+encodedPassword);
        return encodedPassword.equals(MD5Utils.encrypt(rawPassword.toString()));
    }
}
